cd "C:\Users\renan\OneDrive\Dokumenter\bases TSE prefeitas mulheres\bspr"

use "C:\Users\renan\OneDrive\Dokumenter\bases TSE prefeitas mulheres\bspr\base_prefeitos_municipio.dta", clear



set more off

drop NV* N_D* N_E*

*Dropando casos em que Margem de votos igual a missing (chequei e se trata de situa��es em que s� h� um candidato)
drop if margin==.

*Mantendo elei��es em que s� h� um homem e uma mulher concorrendo
keep if D_BASE_HM==1


*Gerando dummy se acima da mediana mulheres na camara ou abaixo
gen d_women_win_councillor=0 if share_VER_MUL<=med_share_VER_MUL
replace d_women_win_councillor=1 if  share_VER_MUL>med_share_VER_MUL


gen d_women_cand_councillor=0 if share_VER_MUL_cand<=med_share_VER_MUL_cand
replace d_women_cand_councillor=1 if  share_VER_MUL_cand>med_share_VER_MUL_cand



*keep if d_women_win_councillor==1
 

*Table 2 
mat R=J(100,16,.)
local row=1
foreach y in  pt psdb pfl pmdb escol1 escol2 escol3 escol4  {

rdrobust `y' margin, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)





local ++row
local ++row
local ++row

}


 

matrix colname R="All" 

putexcel A1=matrix(R) using reg, replace sheet("table 2a")




mat drop R



mat R=J(100,16,.)
local row=1
foreach y in  agua esgoto alfabetizados pop00 gdp00pc mulher theil domrural  {

rdrobust `y' margin, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)





local ++row
local ++row
local ++row

}


 

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table 2b")

mat drop R




*Table 3
mat R=J(100,16,.)
local row=1
foreach y in  pt psdb pfl pmdb agua esgoto alfabetizados pop00 gdp00pc mulher theil domrural {

rdrobust `y' margin if escol4==0, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)

rdrobust `y' margin if escol4==1, all 

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)


local ++row
local ++row
local ++row

}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table 3")
mat drop R



*Table 4

mat R=J(100,16,.)
local row=1
foreach y in  ln_NV_DEPFED_AA_HM ln_NV_DEPEST_AA_HM ln_NV_PRE_A_HM ln_NV_VER_A_HM    {

rdrobust `y' margin if escol4==0, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)

rdrobust `y' margin if escol4==1, all 

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)


local ++row
local ++row
local ++row

}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table 4")

mat drop R


*Table 5
mat R=J(100,16,.)
local row=1
foreach y in  ln_NV_DEPFED_DD_HM ln_NV_DEPEST_DD_HM ln_NV_PRE_D_HM ln_NV_VER_D_HM    {

rdrobust `y' margin if escol4==0, all

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)

rdrobust `y' margin if mandato1_amplo==1 & escol4==0, all

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)

rdrobust `y' margin if mandato2_amplo==1 & escol4==0, all

mat R[`row',3] =e(tau_bc)
mat R[`row'+1,3] = e(se_rb)
mat R[`row'+2,3] = e(h_bw)




rdrobust `y' margin if escol4==1, all

mat R[`row',5] =e(tau_bc)
mat R[`row'+1,5] = e(se_rb)
mat R[`row'+2,5] = e(h_bw)

rdrobust `y' margin if mandato1_amplo==1 & escol4==1, all

mat R[`row',6] =e(tau_bc)
mat R[`row'+1,6] = e(se_rb)
mat R[`row'+2,6] = e(h_bw)

rdrobust `y' margin if mandato2_amplo==1 & escol4==1, all

mat R[`row',7] =e(tau_bc)
mat R[`row'+1,7] = e(se_rb)
mat R[`row'+2,7] = e(h_bw)



local ++row
local ++row
local ++row


}


foreach y in  DEPFED_DD DEPEST_DD PRE_D VER_D   {

rdrobust ln_NV_`y'_HM margin if PREF_`y'==0 & escol4==0, all

mat R[`row',4] =e(tau_bc)
mat R[`row'+1,4] = e(se_rb)
mat R[`row'+2,4] = e(h_bw)


rdrobust ln_NV_`y'_HM margin if PREF_`y'==0 & escol4==1, all

mat R[`row',8] =e(tau_bc)
mat R[`row'+1,8] = e(se_rb)
mat R[`row'+2,8] = e(h_bw)


local ++row
local ++row
local ++row


}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table 5")
mat drop R









*Table 6



mat R=J(100,16,.)
local row=1
foreach y in  ln_NV_DEPFED_DD_HM ln_NV_DEPEST_DD_HM ln_NV_PRE_D_HM ln_NV_VER_D_HM    {

rdrobust `y' margin if escol4==0 & d_women_win_councillor==1, all

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)

rdrobust `y' margin if mandato1_amplo==1 & escol4==0 & d_women_win_councillor==1, all

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)

rdrobust `y' margin if mandato2_amplo==1 & escol4==0 & d_women_win_councillor==1, all

mat R[`row',3] =e(tau_bc)
mat R[`row'+1,3] = e(se_rb)
mat R[`row'+2,3] = e(h_bw)




rdrobust `y' margin if escol4==1 & d_women_win_councillor==1, all

mat R[`row',5] =e(tau_bc)
mat R[`row'+1,5] = e(se_rb)
mat R[`row'+2,5] = e(h_bw)

rdrobust `y' margin if mandato1_amplo==1 & escol4==1 & d_women_win_councillor==1, all

mat R[`row',6] =e(tau_bc)
mat R[`row'+1,6] = e(se_rb)
mat R[`row'+2,6] = e(h_bw)

rdrobust `y' margin if mandato2_amplo==1 & escol4==1 & d_women_win_councillor==1, all

mat R[`row',7] =e(tau_bc)
mat R[`row'+1,7] = e(se_rb)
mat R[`row'+2,7] = e(h_bw)



local ++row
local ++row
local ++row


}


foreach y in  DEPFED_DD DEPEST_DD PRE_D VER_D   {

rdrobust ln_NV_`y'_HM margin if PREF_`y'==0 & escol4==0 & d_women_win_councillor==1, all

mat R[`row',4] =e(tau_bc)
mat R[`row'+1,4] = e(se_rb)
mat R[`row'+2,4] = e(h_bw)


rdrobust ln_NV_`y'_HM margin if PREF_`y'==0 & escol4==1 & d_women_win_councillor==1, all

mat R[`row',8] =e(tau_bc)
mat R[`row'+1,8] = e(se_rb)
mat R[`row'+2,8] = e(h_bw)


local ++row
local ++row
local ++row


}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table 6")
mat drop R



*Table A3
mat R=J(100,15,.)
local row=1
foreach y in  pt psdb pfl pmdb escol1 escol2 escol3 escol4 agua esgoto alfabetizados pop00 gdp00pc mulher theil domrural   {


summarize `y' if mulher_venceu==0

mat R[`row',1] =r(mean)
mat R[`row'+1,1] = r(sd)
mat R[`row'+2,1] = r(N)

summarize `y' if mulher_venceu==1 & escol4==0 & d_women_win_councillor==1

mat R[`row',2] =r(mean)
mat R[`row'+1,2] = r(sd)
mat R[`row'+2,2] = r(N)

local ++row
local ++row
local ++row


}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table a3")
mat drop R


*Table A4
mat R=J(100,15,.)
local row=1
foreach y in  ln_NV_DEPFED_DD_HM ln_NV_DEPEST_DD_HM ln_NV_PRE_D_HM ln_NV_VER_D_HM    {




summarize `y' if mulher_venceu==0 & escol3==0 

mat R[`row',1] =r(mean)
mat R[`row'+1,1] = r(sd)
mat R[`row'+2,1] = r(N)

summarize `y' if mulher_venceu==1 & escol3==0 

mat R[`row',2] =r(mean)
mat R[`row'+1,2] = r(sd)
mat R[`row'+2,2] = r(N)

summarize `y' if mulher_venceu==0 & escol3==1 

mat R[`row',3] =r(mean)
mat R[`row'+1,3] = r(sd)
mat R[`row'+2,3] = r(N)

summarize `y' if mulher_venceu==1 & escol3==1 

mat R[`row',4] =r(mean)
mat R[`row'+1,4] = r(sd)
mat R[`row'+2,4] = r(N)




summarize `y' if mulher_venceu==0 & escol4==0 

mat R[`row',5] =r(mean)
mat R[`row'+1,5] = r(sd)
mat R[`row'+2,5] = r(N)

summarize `y' if mulher_venceu==1 & escol4==0 

mat R[`row',6] =r(mean)
mat R[`row'+1,6] = r(sd)
mat R[`row'+2,6] = r(N)

summarize `y' if mulher_venceu==0 & escol4==1 

mat R[`row',7] =r(mean)
mat R[`row'+1,7] = r(sd)
mat R[`row'+2,7] = r(N)

summarize `y' if mulher_venceu==1 & escol4==1 

mat R[`row',8] =r(mean)
mat R[`row'+1,8] = r(sd)
mat R[`row'+2,8] = r(N)


local ++row
local ++row
local ++row
	

}






putexcel A1=matrix(R) using reg, modify sheet("table a4")
mat drop R






*Table A5
mat R=J(100,16,.)
local row=1
foreach y in  pt psdb pfl pmdb {

rdrobust `y'_MUL margin if escol4==0, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)


rdrobust `y'_MUL margin if escol4==1, all 

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)


rdrobust `y'_HOM margin if escol4==0, all 

mat R[`row',4] =e(tau_bc)
mat R[`row'+1,4] = e(se_rb)
mat R[`row'+2,4] = e(h_bw)


rdrobust `y'_HOM margin if escol4==1, all 

mat R[`row',5] =e(tau_bc)
mat R[`row'+1,5] = e(se_rb)
mat R[`row'+2,5] = e(h_bw)

local ++row
local ++row
local ++row

}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table a5")

mat drop R




*Table A6
mat R=J(100,15,.)
local row=1
foreach y in  ln_NV_DEPFED_DD_HM ln_NV_DEPEST_DD_HM ln_NV_PRE_D_HM ln_NV_VER_D_HM    {




summarize `y' if mulher_venceu==0 & escol4==0 & d_women_win_councillor==1

mat R[`row',1] =r(mean)
mat R[`row'+1,1] = r(sd)
mat R[`row'+2,1] = r(N)

summarize `y' if mulher_venceu==1 & escol4==0 & d_women_win_councillor==1

mat R[`row',2] =r(mean)
mat R[`row'+1,2] = r(sd)
mat R[`row'+2,2] = r(N)

summarize `y' if mulher_venceu==0 & escol4==1 & d_women_win_councillor==1

mat R[`row',3] =r(mean)
mat R[`row'+1,3] = r(sd)
mat R[`row'+2,3] = r(N)

summarize `y' if mulher_venceu==1 & escol4==1 & d_women_win_councillor==1

mat R[`row',4] =r(mean)
mat R[`row'+1,4] = r(sd)
mat R[`row'+2,4] = r(N)




summarize `y' if mulher_venceu==0 & escol4==0 & d_women_win_councillor==0

mat R[`row',6] =r(mean)
mat R[`row'+1,6] = r(sd)
mat R[`row'+2,6] = r(N)

summarize `y' if mulher_venceu==1 & escol4==0 & d_women_win_councillor==0

mat R[`row',7] =r(mean)
mat R[`row'+1,7] = r(sd)
mat R[`row'+2,7] = r(N)

summarize `y' if mulher_venceu==0 & escol4==1 & d_women_win_councillor==0

mat R[`row',8] =r(mean)
mat R[`row'+1,8] = r(sd)
mat R[`row'+2,8] = r(N)

summarize `y' if mulher_venceu==1 & escol4==1 & d_women_win_councillor==0

mat R[`row',9] =r(mean)
mat R[`row'+1,9] = r(sd)
mat R[`row'+2,9] = r(N)


local ++row
local ++row
local ++row
	

}




matrix colname R="All" "First Term" "Second Term" "Mayor is not running" 

putexcel A1=matrix(R) using reg, modify sheet("table a6")
mat drop R




*Table SB1


mat R=J(100,16,.)
local row=1
foreach y in  pt psdb pfl pmdb {

rdrobust `y'_MUL margin if escol4==0 & d_women_win_councillor==1, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)


rdrobust `y'_MUL margin if escol4==1 & d_women_win_councillor==1, all 

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)



rdrobust `y'_MUL margin if escol4==0 & d_women_win_councillor==0, all 

mat R[`row',3] =e(tau_bc)
mat R[`row'+1,3] = e(se_rb)
mat R[`row'+2,3] = e(h_bw)


rdrobust `y'_MUL margin if escol4==1 & d_women_win_councillor==0, all 

mat R[`row',4] =e(tau_bc)
mat R[`row'+1,4] = e(se_rb)
mat R[`row'+2,4] = e(h_bw)



rdrobust `y'_HOM margin if escol4==0 & d_women_win_councillor==1, all 

mat R[`row',6] =e(tau_bc)
mat R[`row'+1,6] = e(se_rb)
mat R[`row'+2,6] = e(h_bw)


rdrobust `y'_HOM margin if escol4==1 & d_women_win_councillor==1, all 

mat R[`row',7] =e(tau_bc)
mat R[`row'+1,7] = e(se_rb)
mat R[`row'+2,7] = e(h_bw)


rdrobust `y'_HOM margin if escol4==0 & d_women_win_councillor==0, all 

mat R[`row',8] =e(tau_bc)
mat R[`row'+1,8] = e(se_rb)
mat R[`row'+2,8] = e(h_bw)


rdrobust `y'_HOM margin if escol4==1 & d_women_win_councillor==0, all 

mat R[`row',9] =e(tau_bc)
mat R[`row'+1,9] = e(se_rb)
mat R[`row'+2,9] = e(h_bw)






local ++row
local ++row
local ++row

}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table sb1")

mat drop R






*Table SB2

mat R=J(100,16,.)
local row=1
foreach y in  pt psdb pfl pmdb agua esgoto alfabetizados pop00 gdp00pc mulher theil domrural {

rdrobust `y' margin if escol4==0 & d_women_win_councillor==1, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)


rdrobust `y' margin if escol4==1 & d_women_win_councillor==1, all 

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)



rdrobust `y' margin if escol4==0 & d_women_win_councillor==0, all 

mat R[`row',3] =e(tau_bc)
mat R[`row'+1,3] = e(se_rb)
mat R[`row'+2,3] = e(h_bw)


rdrobust `y' margin if escol4==1 & d_women_win_councillor==0, all 

mat R[`row',4] =e(tau_bc)
mat R[`row'+1,4] = e(se_rb)
mat R[`row'+2,4] = e(h_bw)





local ++row
local ++row
local ++row

}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table sb2")

mat drop R






*Table SB3

mat R=J(100,16,.)
local row=1
foreach y in  ln_NV_DEPFED_AA_HM ln_NV_DEPEST_AA_HM ln_NV_PRE_A_HM ln_NV_VER_A_HM    {

rdrobust `y' margin if escol4==0 & d_women_win_councillor==1, all 

mat R[`row',1] =e(tau_bc)
mat R[`row'+1,1] = e(se_rb)
mat R[`row'+2,1] = e(h_bw)


rdrobust `y' margin if escol4==1 & d_women_win_councillor==1, all 

mat R[`row',2] =e(tau_bc)
mat R[`row'+1,2] = e(se_rb)
mat R[`row'+2,2] = e(h_bw)



rdrobust `y' margin if escol4==0 & d_women_win_councillor==0, all 

mat R[`row',4] =e(tau_bc)
mat R[`row'+1,4] = e(se_rb)
mat R[`row'+2,4] = e(h_bw)


rdrobust `y' margin if escol4==1 & d_women_win_councillor==0, all 

mat R[`row',5] =e(tau_bc)
mat R[`row'+1,5] = e(se_rb)
mat R[`row'+2,5] = e(h_bw)





local ++row
local ++row
local ++row

}

matrix colname R="All" 

putexcel A1=matrix(R) using reg, modify sheet("table sb3")

mat drop R
